﻿
@using DAL.Models;
@using Newtonsoft.Json;
@using ExpressManagement.Areas.BackSys.ServiceTools;
@using Microsoft.AspNetCore.Http;
@using System.Text
@{
    ViewBag.Title = "新快递登记";
    Layout = "../Shared/_LayoutBase.cshtml";
    string? jsonStr = Context.Session.GetString("detail");
    UserInfo user =null;
    if (jsonStr != null)
    {
        user= JsonConvert.DeserializeObject<UserInfo>(jsonStr);
    }
     
}
@section CssLink{


}
<div id="app">
    <!-- page heading start-->
    <div class="page-heading">
        <h3>
            新快递登记
        </h3>
        <ul class="breadcrumb">
            <li>
                <a href="">物流管理系统</a>
            </li>
            <li class="active"> 快递管理 </li>
            <li class="active"> 新快递登记 </li>
        </ul>
    </div>
    <!-- page heading end-->
    <!--body wrapper start-->
    <section class="wrapper">
        <!-- page start-->
        <div class="row">
            <div class="col-lg-6">
                <section class="panel">
                    <header class="panel-heading">
                        信息填写
                    </header>
                    <div class="panel-body">
                        <form class="form-horizontal adminex-form" method="get">
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">收件人姓名</label>
                                <div id="GetterName_div" class="col-sm-10 ">
                                    <input v-model="GetterName" type="text" class="form-control ">
                                    <span id="GetterName_tip" class="help-block">收件人姓名</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">收件人地址</label>
                                <div id="GetterAddress_div" class="col-sm-10">
                                    <input v-model="GetterAddress" type="text" class="form-control">
                                    <span  id="GetterAddress_tip" class="help-block">收件人地址</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">收件人手机</label>
                                <div id="GetterPhone_div" class="col-sm-10">
                                    <input v-model="GetterPhone" type="text" class="form-control">
                                    <span id="GetterPhone_tip" class="help-block">收件人手机</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">寄件人姓名</label>
                                <div id="SenderName_div" class="col-sm-10">
                                    <input v-model="SenderName" type="text" value="@user.UserName" class="form-control">
                                    <span id="SenderName_tip" class="help-block">寄件人姓名</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">寄件人地址</label>
                                <div id="SenderAddress_div" class="col-sm-10">
                                    <input v-model="SenderAddress" class="form-control" value="@user.ContactAddress.ToString()">
                                    <span id="SenderAddress_tip" class="help-block">寄件人地址</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">寄件人手机</label>
                                <div id="SenderPhone_div" class="col-sm-10">
                                    <input v-model="SenderPhone" class="form-control" value="@user.Phone">
                                    <span id="SenderPhone_tip" class="help-block">寄件人手机</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">寄件备注</label>
                                <div id="SendInfo_div" class="col-sm-10">
                                    <textarea v-model="SendInfo" rows="6" class="form-control"></textarea>
                                    <span id="SendInfo_tip" class="help-block">填写备注信息</span>
                                </div>
                            </div>
                            <div class="form-group center">
                                <div class="col-lg-6">
                                </div>
                                <button type="reset" class="center btn btn-info">重置</button>

                                <button type="button" class="center btn btn-primary" data-toggle="modal" data-target="#addModal">提交</button>
                            </div>

                        </form>
                    </div>
                </section>
                <input id='act' value='keep' style="visibility: hidden">
                <!-- 模态框示例（Modal） -->
                <form method="post" class="form-horizontal" role="form" id="form_data"  style="margin: 20px;">
                    <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close"  data-dismiss="modal" aria-hidden="true">
                                        &times;
                                    </button>
                                    <h4 class="modal-title" id="myModalLabel">
                                        快件信息提交确认
                                    </h4>
                                </div>
                                <div class="modal-body">
                                    <div class="form-group">
                                        <label for="remark" class="col-sm-3 control-label center ">确认要提交吗?</label>
                                        @*<div class="col-sm-9">
                                                <input type="text" class="form-control" id="update_updateDate" name="updateDate">
                                            </div>*@
                                    </div>

                                </div>
                                <div class="modal-footer">
                                    <button  type="button" class="btn btn-default" data-dismiss="modal">
                                        取消
                                    </button>
                                    <!-- <button type="button" onclick="trigger_delete()" class="btn btn-primary" data-dismiss="modal">
                                        确认
                                    </button><span id="tip"> </span> -->
                                    <button type="button" v-on:click="check_form('add')" class="btn btn-primary">
                                        确认
                                    </button>
                                </div>
                            </div><!-- /.modal-content -->
                        </div><!-- /.modal -->
                    </div>
                </form>


                <!--body wrapper end-->



            </div>
            <!-- main content end-->
        </div>
    </section>
</div>

@section JavascriptLink{

}
@section Javascript{

    <script>
         var vm = new Vue({
                el: "#app",
                  data: {
                   mode :'',
                   TrueName: '',
                   Idcard: '',
                   AddTime: '',
                   UpdateTime: '',
                   Address:'',
                   Email: '',
                   ContactAddress: '',
                   Title:'',
                   Info: '',
                   BagId: '',
                   SendDate: '',
                   GetterName: '',
                   SenderName: '',
                   SenderPhone: '',
                   SenderAddress: '',
                   SendInfo: '',
                   UpdateInfo: '',
                   UpdateDate:'',
                   GetterPhone: '',
                   GetterAddress:'',
                },
               methods: {
                   empty_check: function () {
                       if (!this.GetterName) {
                           return false;
                       }
                       if (!this.GetterAddress) {
                           return false;
                       }
                       if (!this.GetterPhone) {
                           return false;
                       }
                       if (!this.SenderName) {
                           return false;
                       }
                       if (!this.SenderAddress) {
                           return false;
                       }
                       if (!this.SenderPhone) {
                           return false;
                       }
                       return true;
                   },

                        // 提交表单
                   check_form: function (act) {

                       if (!this.empty_check()) {
                           $('#addModal').modal('hide');
                           commonUtil.alert('错误','输入有误', 'danger');
                           return false;
                       }
                       var form_data = $('#form_data').serialize();
                       var sendData = new FormData();
                       var sendUrl = "@Url.Action("Add", "Bag")";
                       sendData.append('ID', this.ID);
                       sendData.append('Action', act);
                       sendData.append('SendDate', this.SendDate);
                       sendData.append('GetterName', this.GetterName);
                       sendData.append('GetterPhone', this.GetterPhone);
                       sendData.append('GetterAddress', this.GetterAddress);
                       sendData.append('SenderName', this.SenderName);
                       sendData.append('SenderPhone', this.SenderPhone);
                       sendData.append('SenderAddress', this.SenderAddress);
                       sendData.append('SendInfo', this.SendInfo);

                       //console.log(sendData);
                       // 异步提交数据到Action/GetBagItemByID页面
                       axios({
                           url: sendUrl,
                           method: "post",
                           responseType: 'json',
                           data: sendData,
                           transformRequest: [function (data) {
                               // 对 data 进行任意转换处理
                               //$("#tip").html("<span style='color:blue'>正在处理...</span>");
                               return data;
                           }],
                           // `transformResponse` 在传递给 then/catch 前，允许修改响应数据
                           transformResponse: [function (data) {
                               // 对 data 进行任意转换处理
                               return data;
                           }],

                       }).then((data) => {
                           if (data.data > 0) {
                               //$("#tip").html("<span style='color:blueviolet'>" + act + "成功！</span>");
                               // document.location.href='system_notice.php'
                               commonUtil.alert('成功','注册成功', 'success');
                               $('#addModal').modal('hide');
                               //alert(act + "OK！");
                           }
                           else {
                               //$("#tip").html("<span style='color:red'>失败，请重试</span>");
                               commonUtil.alert('失败','操作失败','danger');
                               $('#addModal').modal('hide');
                           }
                       }).catch(error => {
                           alert(error);
                           $('#addModal').modal('hide');
                       });

                    },



                },
                watch: {
                    //GetterName: {
                    //    deep: true,
                    //    handler(obj) {
                    //        if (!this.GetterName) {
                    //            $('#GetterName_div')[0].className = 'col-sm-10 has-error';
                    //            $('#GetterName_tip')[0].innerText = '收件人姓名输入不合法';
                    //        } else {
                    //            $('#GetterName_div')[0].className = 'col-sm-10 has-success';
                    //            $('#GetterName_tip')[0].innerText = '输入正确 ';
                    //        }
                    //    }
                    //},
                    //GetterAddress: {
                    //    deep: true,
                    //    handler(obj) {
                    //        if (!this.GetterAddress) {
                    //            $('#GetterAddress_div')[0].className = 'col-sm-10 has-error';
                    //            $('#GetterAddress_tip')[0].innerText = '收件人地址输入不合法';
                    //            flag = false;
                    //        } else {
                    //            $('#GetterAddress_div')[0].className = 'col-sm-10 has-success';
                    //            $('#GetterAddress_tip')[0].innerText = '输入正确 ';
                    //        }
                    //    }
                    //},
                    //GetterPhone: {
                    //    deep: true,
                    //    handler(obj) {
                    //        if (!this.GetterPhone) {
                    //            $('#GetterPhone_div')[0].className = 'col-sm-10 has-error';
                    //            $('#GetterPhone_tip')[0].innerText = '收件人地址输入不合法';
                    //            flag = false;
                    //        } else {
                    //            $('#GetterPhone_div')[0].className = 'col-sm-10 has-success';
                    //            $('#GetterPhone_tip')[0].innerText = '输入正确';
                    //        }
                    //    }
                    //},
                    //SenderName: {
                    //    deep: true,
                    //    handler(obj) {
                    //        if (!this.SenderName) {
                    //            $('#SenderName_div')[0].className = 'col-sm-10 has-error';
                    //            $('#SenderName_tip')[0].innerText = '发件人姓名输入不合法';
                    //            flag = false;
                    //        } else {
                    //            $('#SenderName_div')[0].className = 'col-sm-10 has-success';
                    //            $('#SenderName_tip')[0].innerText = '输入正确';
                    //        }
                    //    }
                    //},
                    //SenderAddress: {
                    //    deep: true,
                    //    handler(obj) {
                    //        if (!this.SenderAddress) {
                    //            $('#SenderAddress_div')[0].className = 'col-sm-10 has-error';
                    //            $('#SenderAddress_tip')[0].innerText = '发件人地址输入不合法';
                    //            flag = false;
                    //        } else {
                    //            $('#SenderAddress_div')[0].className = 'col-sm-10 has-success';
                    //            $('#SenderAddress_tip')[0].innerText = '输入正确';
                    //        }
                    //    }
                    //},
                    //SenderPhone: {
                    //    deep: true,
                    //    handler(obj) {
                    //        if (!this.SenderPhone) {
                    //            $('#SenderPhone_div')[0].className = 'col-sm-10 has-error';
                    //            $('#SenderPhone_tip')[0].innerText = '发件人手机号输入不合法';
                    //            flag = false;
                    //        } else {
                    //            $('#SenderPhone_div')[0].className = 'col-sm-10 has-success';
                    //            $('#SenderPhone_tip')[0].innerText = '输入正确';
                    //        }
                    //    }
                    //}
               },
             mounted: function () {
                 this.SenderName = '@user.UserName';
                 this.SenderPhone = '@user.Phone';
                 this.SenderAddress = '@user.ContactAddress';
               },
               created() {

                }
            });
    </script>
}
